package com.asp.alumnisystem.ui;

import android.app.Activity;
import android.content.Intent;
import android.widget.EditText;

import com.asp.alumnisystem.R;
import com.asp.alumnisystem.base.BaseActivity;
import com.asp.alumnisystem.base.BaseBean;
import com.asp.alumnisystem.base.BasePresenter;
import com.asp.alumnisystem.base.IView;
import com.asp.alumnisystem.model.DetailsModel;
import com.asp.alumnisystem.presenter.ReplyPresenter;
import com.asp.alumnisystem.utils.DialogUtils;
import com.asp.alumnisystem.utils.ToastUtil;
import com.asp.alumnisystem.view.TitleBar;

import butterknife.BindView;

/**
 * 回复帖子界面
 */
public class ReplyActivity extends BaseActivity implements IView<DetailsModel> {

    @BindView(R.id.title_bar)
    TitleBar titleBar;

    @BindView(R.id.edit_text)
    EditText editText;

    private ReplyPresenter presenter;

    @Override
    protected int getLayoutId() {
        return R.layout.publish_layout;
    }

    @Override
    protected void initView() {
        presenter = new ReplyPresenter(this, getIntent().getLongExtra("id", 0));
        managerPresenter(presenter);
        titleBar.setTitleStr("回复");
        titleBar.setOptStr("发布");
        titleBar.setListener(new TitleBar.OnTitleBarClickListener() {
            @Override
            public boolean onClickBackView() {
                return false;
            }

            @Override
            public void onClickOptView() {
                presenter.work(editText.getText().toString());
            }
        });
    }

    @Override
    public void onBack() {
        finish();
    }

    @Override
    public void loadSuccess(BasePresenter presenter, BaseBean<DetailsModel> result) {
        if (result.success){
            ToastUtil.showShortToast("回复成功！");
            Intent intent = new Intent();
            intent.putExtra("model", result.data);
            setResult(Activity.RESULT_OK, intent);
            finish();
        }else{
            ToastUtil.showShortToast(result.error);
        }
    }

    @Override
    public void loadStart(BasePresenter presenter) {
        super.loadStart(presenter);
        DialogUtils.showLoadDialog(this, "回复中...");
    }

    @Override
    public void loadFail(BasePresenter presenter, String error) {
        super.loadFail(presenter, error);
        ToastUtil.showShortToast(error);
    }

    @Override
    public void loadDone(BasePresenter presenter) {
        super.loadDone(presenter);
        DialogUtils.dismiss();
    }

}
